import 'babel-polyfill'
import controller from './controller.js'

async function createTags () {

	const topTags = await controller.createTag([
			{
				name: '类型'
			},
			{
				name: '地点'
			}
		])

	const commonTags = await controller.createTag([
			{
				name: '证件',
				fatherId: topTags[0]._id
			},
			{
				name: '钥匙',
				fatherId: topTags[0]._id
			},
			{
				name: '书/纸质材料',
				fatherId: topTags[0]._id
			},
			{	
				name: '手机',
				fatherId: topTags[0]._id
			},
			{	
				name: '钱包',
				fatherId: topTags[0]._id
			},
			{	
				name: '书包/背包类',
				fatherId: topTags[0]._id
			},
			{
				name: '衣物',
				fatherId: topTags[0]._id
			},
			{
				name: '其他',
				fatherId: topTags[0]._id
			}
		])
}

async function clear () {
	const result = await controller.deleteAll()
	console.log('clear result: ', result)
}

async function init () {
	const tags = await controller.getAll()
	if (tags.length > 0 && tags.length == 6) return
	await clear()
	await createTags()
}

export default init
